/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ibuonline.b2b.admin.service;

import com.dimeng.common.base.BaseServiceImpl;
import com.ibuonline.b2b.entity.ProdPicture;
import com.ibuonline.b2b.entity.ShopAlbumPhoto;
import com.ibuonline.b2b.product.dao.ProductPictureDAO;
import com.ibuonline.b2b.shop.dao.ShopPhotoDAO;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author daojindi-yf
 */
public class PhotoCheckManageServiceImpl extends BaseServiceImpl<ShopAlbumPhoto> implements PhotoCheckManageService {

    private ShopPhotoDAO shopPhotoDAO;
    private ProductPictureDAO prodPictureDAO;

    @Override
    public List<ShopAlbumPhoto> getCompanyAllPhoto(Integer companyId) {
        String hql = "select sap from ShopAlbumPhoto sap,ShopAlbum sa where sap.albumId=sa.id and sa.companyId = ? order by sap.createTime desc";
        List<ShopAlbumPhoto> list = shopPhotoDAO.query(hql, companyId);
        return list;
    }

    @Override
    public List<ShopAlbumPhoto> getProductAlllPhoto(Long productId) {
        List<ProdPicture> prodPicture = prodPictureDAO.getByParam("prodId", productId);
        List<ShopAlbumPhoto> prodPictures = new ArrayList<ShopAlbumPhoto>();
        for (int i = 0; i < prodPicture.size(); i++) {
            ProdPicture prodPic = prodPicture.get(i);
            ShopAlbumPhoto shopPhoto = shopPhotoDAO.get(prodPic.getPhotoId());
            if (shopPhoto != null) {
                prodPictures.add(shopPhoto);
                if (prodPictures.size() >= 3) {
                    break;
                }
            }
        }
        return prodPictures;
    }

    public void changePhotoCheckStatus(Long sapId, String status) {
        ShopAlbumPhoto shopPhoto = shopPhotoDAO.get(sapId);
        if(shopPhoto!=null){
            if(!shopPhoto.getStatus().equals(status)){
                shopPhoto.setStatus(status);
                shopPhotoDAO.save(shopPhoto);
            }
        }
    }

    public ProductPictureDAO getProdPictureDAO() {
        return prodPictureDAO;
    }

    public void setProdPictureDAO(ProductPictureDAO prodPictureDAO) {
        this.prodPictureDAO = prodPictureDAO;
    }

    public ShopPhotoDAO getShopPhotoDAO() {
        return shopPhotoDAO;
    }

    public void setShopPhotoDAO(ShopPhotoDAO shopPhotoDAO) {
        this.shopPhotoDAO = shopPhotoDAO;
    }
}
